﻿using Microsoft.Practices.Prism.Events;
using SpeakToMe.Core;
using SpeakToMe.Core.Enums;
using SpeakToMe.Core.Events;
using SpeakToMe.Core.Interfaces;
using SpeakToMe.Speech;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SpeakToMe.Presence
{
    [Export]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class TestPresence : IPresence
    {
        [Import]
        public IEventAggregator EventAggregator { get; set; }

        public bool IsConnected
        {
            get { return true; }
        }

        public void Initialize()
        {
            //do nothing
        }

        private void ReplyToChannelEventHandler(ReplyToChannelEventArgs args)
        {
            if (args.Mode == ConversationType.Test)
            {
                //ConversationData.CreateConversationHistory(args.ConversationId, args.Reply, args.TagString, args.Tag, false);

                if (args.Callback != null)
                {
                    args.Callback.ReturnResult(args.Reply);
                }
            }
        }

        public void OnImportsSatisfied()
        {
            this.EventAggregator.GetEvent<ReplyToChannelEvent>().Subscribe(ReplyToChannelEventHandler);
        }

        public void ProcessCommand(string command, int userId, ISmartHomeServiceCallback callback)
        {
            var processor = ServiceLocator.GetInstance<CommandProcessor>();
            processor.ProcessCommand(command, userId, ConversationType.Test, "", callback);
        }
    }
}
